#include <iostream>
#include <cmath>
#include <cassert>
#include <vector>

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>

#include <set>

#include "matrix.h"
#include "matrix_util.h"
#include "primitive.h"
#include "mesh.h"
#include "aabbtree.h"

#include "intersect_2d.h"
#include "intersect_3d.h"

const double tiny_value = 1e-5 ;
typedef double Value;
//typedef long double Value; 

/*
#ifndef CORE_LEVEL
#   define CORE_LEVEL 3
#endif

#define CORE_NO_AUTOMATIC_NAMESPACE
#define GLFLOAT(VAL) \
        VAL.doubleValue()

#include "CORE/CORE.h" 

typedef CORE::Expr Value ;
*/

typedef typename MeshPrimitive<Value>::PointType     PointType  ;
typedef typename MeshPrimitive<Value>::VectorType    VectorType ;
typedef typename MeshPrimitive<Value>::FaceType      FaceType   ;
typedef typename MeshPrimitive<Value>::VertexType    VertexType ;
typedef Mesh <MeshPrimitive<Value> >                 MeshType ;

typedef AABBTreePoly <Value>                         AABBTreePolyType;
typedef AABBTreePolyBuilder <Value>                  AABBTreePolyBuilderType  ;
typedef AABBTreePolygon <Value>                      AABBTreePolygonType ;
typedef AABBTreeNode <Value> AABBTreeNodeType ;
typedef Box<Value> BoxType;
typedef Segment<Value> SegmentType;
typedef Polygon<Value> PolygonType;


#define CPPUNIT_ASSERT assert 
/**
 * Co-planar triangle vertex intersect vertex. 
 */
void test_tri_tri_3d_co_01()
{
	try
	{
		Vector<Value> p1, q1, r1 ;  // First triangle. 
		Vector<Value> p2, q2, r2 ;  // Second triangle. 


		p1 = Vector<Value> (Value (1.0), Value(1.0), Value(1e-54));
		q1 = Vector<Value> (Value (0.0), Value(1.0), Value(1e-54));
		r1 = Vector<Value> (Value (1.718281828e-54), Value(0.103), Value(1e-54));

		p2 = Vector<Value> (Value (-1.0), Value(0.0), Value(1e-54));
		q2 = Vector<Value> (Value (-1.0), Value(-1.0), Value(1e-54));
		r2 = Vector<Value> (Value (1.718281828e-54), Value(0.103), Value(1e-54));


		PolygonType polygon1 , polygon2 ;
		polygon1.append_vertex(p1); 
		polygon1.append_vertex(q1); 
		polygon1.append_vertex(r1);

		polygon2.append_vertex(p2); 
		polygon2.append_vertex(q2); 
		polygon2.append_vertex(r2);

		IntersectResult<Value> res; 
		CPPUNIT_ASSERT (true == intersect_tri_tri (polygon1, polygon2, res ));
		CPPUNIT_ASSERT (POINT == res.res_type);
		CPPUNIT_ASSERT (r1 == res.point);
//			std::cout<<res.point<<std::endl;
	}
	catch (const char * msg)
	{
		std::cerr<<msg<<std::endl;
		throw (msg);
	}
}

/**
 * Co-planar triangles. Vertex intersects vertex. Silver triangles. 
 */
void test_tri_tri_3d_co_02()
{
	try
	{
		Vector<Value> p1, q1, r1 ;  // First triangle. 
		Vector<Value> p2, q2, r2 ;  // Second triangle. 

		p1 = Vector<Value> (Value (0.0), Value(1.0), Value(1e54));
		q1 = Vector<Value> (Value (1.0), Value(1.0), Value(1e54));
		r1 = Vector<Value> (Value (1.718281828e-54), Value(1.03e128), Value(1e54));

		p2 = Vector<Value> (Value (-1.0), Value(0.0), Value(1e54));
		r2 = Vector<Value> (Value (-1.0), Value(-1.0), Value(1e54));
		q2 = Vector<Value> (Value (1.718281828e-54), Value(1.03e128), Value(1e54));


		PolygonType polygon1 , polygon2 ;
		polygon1.append_vertex(p1); 
		polygon1.append_vertex(q1); 
		polygon1.append_vertex(r1);

		polygon2.append_vertex(p2); 
		polygon2.append_vertex(q2); 
		polygon2.append_vertex(r2);

		IntersectResult<Value> res; 
		CPPUNIT_ASSERT (true == intersect_tri_tri (polygon1, polygon2, res ));
		CPPUNIT_ASSERT (POINT == res.res_type);
		CPPUNIT_ASSERT (r1 == res.point);
	}
	catch (const char * msg)
	{
		std::cerr<<msg<<std::endl;
		throw (msg);			
	}
}

/**
 * Co-planar triangles. None-intersect. 
 */
void test_tri_tri_3d_co_03()
{
	try
	{
		Vector<Value> p1, q1, r1 ;  // First triangle. 
		Vector<Value> p2, q2, r2 ;  // Second triangle. 

		p1 = Vector<Value> (Value (0.0), Value(1.0), Value(1e54));
		q1 = Vector<Value> (Value (1.0), Value(1.0), Value(1e54));
		r1 = Vector<Value> (Value (1.123456789e-54), Value(1.03e128), Value(1e54));

		p2 = Vector<Value> (Value (-1.0), Value(0.0), Value(1e54));
		q2 = Vector<Value> (Value (1.123456788e-54), Value(1.03e-128), Value(1e54));
		r2 = Vector<Value> (Value (-1.0), Value(-1.0), Value(1e54));

		PolygonType polygon1 , polygon2 ;
		polygon1.append_vertex(p1); 
		polygon1.append_vertex(q1); 
		polygon1.append_vertex(r1);

		polygon2.append_vertex(p2); 
		polygon2.append_vertex(q2); 
		polygon2.append_vertex(r2);

		CPPUNIT_ASSERT (false == predicate_polygon_polygon (polygon1, polygon2 ));
	}
	catch (const char * msg)
	{
		std::cerr<<msg<<std::endl;
		throw (msg);			
	}

}

/**
 * Co-planar triangles. Vertex intersect edges. 
 */
void test_tri_tri_3d_co_04()
{
	try
	{
		Vector<Value> p1, q1, r1 ;  // First triangle. 
		Vector<Value> p2, q2, r2 ;  // Second triangle. 

		p1 = Vector<Value> (Value (0.0), Value(1e-54), Value(1e128));
		q1 = Vector<Value> (Value (1e-54), Value(1e-54), Value(1e128));
		r1 = Vector<Value> (Value (2e-54), Value(1e103), Value(1e128));

		p2 = Vector<Value> (Value (0.5e-54), Value(1e-54), Value(1e128));
		q2 = Vector<Value> (Value (3e-54), Value(-1e-54), Value(1e128));
		r2 = Vector<Value> (Value (4e-54), Value(-1e-54), Value(1e128));


		PolygonType polygon1 , polygon2 ;
		polygon1.append_vertex(p1); 
		polygon1.append_vertex(q1); 
		polygon1.append_vertex(r1);

		polygon2.append_vertex(p2); 
		polygon2.append_vertex(q2); 
		polygon2.append_vertex(r2);

		IntersectResult<Value> res; 
		CPPUNIT_ASSERT (true == intersect_tri_tri (polygon1, polygon2, res ));
		CPPUNIT_ASSERT (POINT == res.res_type );
		CPPUNIT_ASSERT (res.point == p2);
	}
	catch (const char * msg)
	{
		std::cerr<<msg<<std::endl;
		throw (msg);			
	}
}
/**
 * Co-planar normal intersection. Return a polygon. 
 */
void test_tri_tri_3d_co_05()
{
	try
	{
		Vector<Value> p1, q1, r1 ;  // First triangle. 
		Vector<Value> p2, q2, r2 ;  // Second triangle. 

		p1 = Vector<Value> (Value (0.2), Value(0.0), Value(1e128));
		q1 = Vector<Value> (Value (1.0), Value(0.0), Value(1e128));
		r1 = Vector<Value> (Value (0.2), Value(0.8), Value(1e128));

		p2 = Vector<Value> (Value (0.0), Value(0.0), Value(1e128));
		q2 = Vector<Value> (Value (1.0), Value(1.0), Value(1e128));
		r2 = Vector<Value> (Value (0.0), Value(1.0), Value(1e128));


		PolygonType polygon1 , polygon2 ;
		polygon1.append_vertex(p1); 
		polygon1.append_vertex(q1); 
		polygon1.append_vertex(r1);

		polygon2.append_vertex(p2); 
		polygon2.append_vertex(q2); 
		polygon2.append_vertex(r2);

		IntersectResult<Value> res; 
		CPPUNIT_ASSERT (true == intersect_tri_tri (polygon1, polygon2, res ));
		CPPUNIT_ASSERT (POLYGON == res.res_type );
		std::cout<<res.polygon<<std::endl;
	}
	catch (const char * msg)
	{
		std::cerr<<msg<<std::endl;
		throw (msg);			
	}
}
void test_tri_tri_3d_co_06()
{
}
void test_tri_tri_3d_co_07()
{
}
void test_tri_tri_3d_co_08()
{
}
void test_tri_tri_3d_co_09()
{
}
void test_tri_tri_3d_co_10()
{
}

void test_pol_pol_convex_01()
{
	try
	{
		Vector<Value> p1, q1, r1 ;  // First triangle. 
		Vector<Value> p2, q2, r2 ;  // Second triangle. 

		
//0 0:[1,0,0.5] [0.5,0,0.5] [0.5,0,1] 
//1 7:[0.9,0,0.34] [0.4,0,0.84] [0.9,0,0.84] 

//[1,1,-1] [1,-1,-1] [-1,-1,-1] [-1.2,0.4,1] [-1.2,2.4,-1] [-1.2,0.4,-1] coplanar 0


		p1 = Vector<Value> (Value (1.0), Value(0.0), Value(0.5));		
		q1 = Vector<Value> (Value (0.5), Value(0.0), Value(0.5));
		r1 = Vector<Value> (Value (0.5), Value(0.0), Value(1.0));

		p2 = Vector<Value> (Value (0.9), Value(0.0), Value(0.34));
		q2 = Vector<Value> (Value (0.4), Value(0.0), Value(0.84));
		r2 = Vector<Value> (Value (0.9), Value(0.0), Value(0.84));
		
		
		/*
		//  co-planar polygon. 
		p1 = Vector<Value> (Value (-0.75), Value(0.75), Value(-1.0));
		q1 = Vector<Value> (Value (-1.0), Value(0.75), Value(-1.0));
		r1 = Vector<Value> (Value (-1.0), Value(1.0), Value(-1.0));

		p2 = Vector<Value> (Value (0.138106), Value(-0.881922), Value(-1.0));
		q2 = Vector<Value> (Value (0.066673), Value(-0.881922), Value(-1.0));
		r2 = Vector<Value> (Value (0.007153), Value(-0.83147), Value(-1.0));
		*/

		PolygonType polygon1 , polygon2 ;
		polygon1.append_vertex(p1); polygon1.append_vertex(q1); polygon1.append_vertex(r1);
		polygon2.append_vertex(p2); polygon2.append_vertex(q2); polygon2.append_vertex(r2);
		CPPUNIT_ASSERT (true == predicate_polygon_polygon (polygon1, polygon2 ));		

		
		PolygonType polygon3 ; 
		polygon3.append_vertex(r2); polygon3.append_vertex(p2); polygon3.append_vertex(q2);  
		CPPUNIT_ASSERT (true == predicate_polygon_polygon (polygon1, polygon3 ));		


		PolygonType polygon4 ; 
		polygon4.append_vertex(q2); polygon4.append_vertex(r2); polygon4.append_vertex(p2);  
		CPPUNIT_ASSERT (true == predicate_polygon_polygon (polygon1, polygon4 ));		

		
		
		PolygonType polygon5 ; 
		polygon5.append_vertex(r2); polygon5.append_vertex(q2); polygon5.append_vertex(p2);  
		CPPUNIT_ASSERT (true == predicate_polygon_polygon (polygon1, polygon5 ));		

		PolygonType polygon6 ;
		polygon6.append_vertex(r1); polygon6.append_vertex(q1); polygon6.append_vertex(p1);
		CPPUNIT_ASSERT (true == predicate_polygon_polygon (polygon6, polygon2 ));		
		CPPUNIT_ASSERT (true == predicate_polygon_polygon (polygon6, polygon3 ));		
		CPPUNIT_ASSERT (true == predicate_polygon_polygon (polygon6, polygon4 ));		
		CPPUNIT_ASSERT (true == predicate_polygon_polygon (polygon6, polygon5 ));		


		CPPUNIT_ASSERT (true == predicate_polygon_polygon (polygon2, polygon6 ));		
		CPPUNIT_ASSERT (true == predicate_polygon_polygon (polygon3, polygon6 ));		
		CPPUNIT_ASSERT (true == predicate_polygon_polygon (polygon4, polygon6 ));		
		CPPUNIT_ASSERT (true == predicate_polygon_polygon (polygon5, polygon6 ));	
		
	}
	catch (const char * msg)
	{
		std::cerr<<msg<<std::endl;
		throw (msg);			
	}

}

void test_pol_pol_convex_02()
{
	try
	{
		Vector<Value> p1, q1, r1 ;  // First triangle. 
		Vector<Value> p2, q2, r2 ;  // Second triangle. 

		
		/*
		// General position
		p1 = Vector<Value> (Value (3.0), Value(0.0), Value(-1.0));              
		q1 = Vector<Value> (Value (1.0), Value(0.0), Value(-1.0));
		r1 = Vector<Value> (Value (2.0), Value(0.0), Value(1.0));

		p2 = Vector<Value> (Value (4.0), Value(0.0), Value(0.0));
		q2 = Vector<Value> (Value (2.0), Value(0.0), Value(0.0));
		r2 = Vector<Value> (Value (2.0), Value(-1.0), Value(0.0));
		*/

//        co-planar position 
		p1 = Vector<Value> (Value (1.0), Value(0.0), Value(0.5));		
		q1 = Vector<Value> (Value (0.5), Value(0.0), Value(0.5));
		r1 = Vector<Value> (Value (0.5), Value(0.0), Value(1.0));

		p2 = Vector<Value> (Value (0.9), Value(0.0), Value(0.34));
		q2 = Vector<Value> (Value (0.4), Value(0.0), Value(0.84));
		r2 = Vector<Value> (Value (0.9), Value(0.0), Value(0.84));
		
		/*
		//  co-planar polygon. 
		p1 = Vector<Value> (Value (-0.75), Value(0.75), Value(-1.0));
		q1 = Vector<Value> (Value (-1.0), Value(0.75), Value(-1.0));
		r1 = Vector<Value> (Value (-1.0), Value(1.0), Value(-1.0));

		p2 = Vector<Value> (Value (0.138106), Value(-0.881922), Value(-1.0));
		q2 = Vector<Value> (Value (0.066673), Value(-0.881922), Value(-1.0));
		r2 = Vector<Value> (Value (0.007153), Value(-0.83147), Value(-1.0));

		p1 = Vector<Value> (Value (3.0), Value(0.0), Value(-1.0));              
		q1 = Vector<Value> (Value (1.0), Value(0.0), Value(-1.0));
		r1 = Vector<Value> (Value (2.0), Value(0.0), Value(1.0));

		p2 = Vector<Value> (Value (4.0), Value(0.0), Value(0.0));
		q2 = Vector<Value> (Value (2.0), Value(0.0), Value(0.0));
		r2 = Vector<Value> (Value (2.0), Value(-1.0), Value(0.0));

		*/

		IntersectResult<Value> res; 
		PolygonType polygon1 , polygon2 ;



		polygon1.append_vertex(p1); polygon1.append_vertex(q1); polygon1.append_vertex(r1);


		polygon2.append_vertex(p2); polygon2.append_vertex(q2); polygon2.append_vertex(r2);
		CPPUNIT_ASSERT (true == intersect_polygon_polygon (polygon1, polygon2, res ));	
		if (res.res_type == SEGMENT) std::cout<<"S "<<res.segment<<std::endl;
		else if (res.res_type == POINT )std::cout<<"P "<<res.point<<std::endl;
		else if (res.res_type == POLYGON) std::cout<<"Q "<<res.polygon<<std::endl;

		
		PolygonType polygon3 ; 
		polygon3.append_vertex(r2); polygon3.append_vertex(p2); polygon3.append_vertex(q2);  
		CPPUNIT_ASSERT (true == intersect_polygon_polygon (polygon1, polygon3, res ));		
		if (res.res_type == SEGMENT) std::cout<<"S "<<res.segment<<std::endl;
		else std::cout<<"S "<<res.point<<std::endl;


		PolygonType polygon4 ; 
		polygon4.append_vertex(q2); polygon4.append_vertex(r2); polygon4.append_vertex(p2);  
		CPPUNIT_ASSERT (true == intersect_polygon_polygon (polygon1, polygon4, res ));		
		if (res.res_type == SEGMENT) std::cout<<"S "<<res.segment<<std::endl;
		else std::cout<<"S "<<res.point<<std::endl;

		PolygonType polygon5 ; 
		polygon5.append_vertex(r2); polygon5.append_vertex(q2); polygon5.append_vertex(p2);  
		CPPUNIT_ASSERT (true == intersect_polygon_polygon (polygon1, polygon5, res ));		
		if (res.res_type == SEGMENT) std::cout<<"S "<<res.segment<<std::endl;
		else std::cout<<"S "<<res.point<<std::endl;
				

		PolygonType polygon6 ;
		polygon6.append_vertex(r1); polygon6.append_vertex(q1); polygon6.append_vertex(p1);
		CPPUNIT_ASSERT (true == intersect_polygon_polygon (polygon6, polygon2, res ));		
		if (res.res_type == SEGMENT) std::cout<<"S "<<res.segment<<std::endl;
		else std::cout<<"S "<<res.point<<std::endl;

		CPPUNIT_ASSERT (true == intersect_polygon_polygon (polygon6, polygon3, res ));		
		if (res.res_type == SEGMENT) std::cout<<"S "<<res.segment<<std::endl;
		else std::cout<<"S "<<res.point<<std::endl;

		CPPUNIT_ASSERT (true == intersect_polygon_polygon (polygon6, polygon4, res ));		
		if (res.res_type == SEGMENT) std::cout<<"S "<<res.segment<<std::endl;
		else std::cout<<"S "<<res.point<<std::endl;

		CPPUNIT_ASSERT (true == intersect_polygon_polygon (polygon6, polygon5, res ));		
		if (res.res_type == SEGMENT) std::cout<<"S "<<res.segment<<std::endl;
		else std::cout<<"S "<<res.point<<std::endl;


		CPPUNIT_ASSERT (true == intersect_polygon_polygon (polygon2, polygon6, res ));		
		if (res.res_type == SEGMENT) std::cout<<"S "<<res.segment<<std::endl;
		else std::cout<<"S "<<res.point<<std::endl;

		CPPUNIT_ASSERT (true == intersect_polygon_polygon (polygon3, polygon6, res ));		
		if (res.res_type == SEGMENT) std::cout<<"S "<<res.segment<<std::endl;
		else std::cout<<"S "<<res.point<<std::endl;

		CPPUNIT_ASSERT (true == intersect_polygon_polygon (polygon4, polygon6, res ));		
		if (res.res_type == SEGMENT) std::cout<<"S "<<res.segment<<std::endl;
		else std::cout<<"S "<<res.point<<std::endl;

		CPPUNIT_ASSERT (true == intersect_polygon_polygon (polygon5, polygon6, res ));	
		if (res.res_type == SEGMENT) std::cout<<"S "<<res.segment<<std::endl;
		else std::cout<<"S "<<res.point<<std::endl;

		
	}
	catch (const char * msg)
	{
		std::cerr<<msg<<std::endl;
		throw (msg);			
	}


}

void test_pol_pol_convex_03()
{
	try
	{
		Vector<Value> p1, q1, r1 ;  // First triangle. 
		Vector<Value> p2, q2, r2 ;  // Second triangle. 
        //Pol1 [0,1,1] [0,1,0] [-1,1,0] 
        //Pol2 [1,1,0] [1,1,-1] [0,1,0]

		
//0 0:[1,0,0.5] [0.5,0,0.5] [0.5,0,1] 
//1 7:[0.9,0,0.34] [0.4,0,0.84] [0.9,0,0.84] 

//[1,1,-1] [1,-1,-1] [-1,-1,-1] [-1.2,0.4,1] [-1.2,2.4,-1] [-1.2,0.4,-1] coplanar 0
//[1,3] [1,1,-1] [-1,-1,-1] [-1,1,-1] [-1.2,0.4,1] [-1.2,2.4,-1] [-1.2,0.4,-1]
//[4,7] [1,-1,1] [1,1,1] [-1,-1,1] [0.8,2.4,-1] [0.8,2.4,1] [0.8,0.4,1] 
		/*
		p1 = Vector<Value> (Value (1), Value(1), Value(-1));		
		q1 = Vector<Value> (Value (1), Value(-1), Value(-1));
		r1 = Vector<Value> (Value (-1), Value(-1), Value(-1));

		p2 = Vector<Value> (Value (-1.2), Value(0.4), Value(1));
		q2 = Vector<Value> (Value (-1.2), Value(2.4), Value(-1));
		r2 = Vector<Value> (Value (-1.2), Value(0.4), Value(-1));
		*/
		/*
		//  co-planar polygon. 
		p1 = Vector<Value> (Value (1), Value(1), Value(-1.0));
		q1 = Vector<Value> (Value (-1.0), Value(-1), Value(-1.0));
		r1 = Vector<Value> (Value (-1.0), Value(1.0), Value(-1.0));

		p2 = Vector<Value> (Value (-1.2), Value(0.4), Value(1));
		q2 = Vector<Value> (Value (-1.2), Value(2.4), Value(-1));
		r2 = Vector<Value> (Value (-1.2), Value(0.4), Value(-1));
		*/
		/*
		p1 = Vector<Value> (Value (1), Value(-1), Value(1.0));
		q1 = Vector<Value> (Value (1.0), Value(1), Value(1.0));
		r1 = Vector<Value> (Value (-1.0), Value(-1.0), Value(1.0));

		p2 = Vector<Value> (Value (0.8), Value(2.4), Value(-1));
		q2 = Vector<Value> (Value (0.8), Value(2.4), Value(1));
		r2 = Vector<Value> (Value (0.8), Value(0.4), Value(1));
		*/

		p1 = 1,1,-1 ;
		q1 = 1,-1,-1; 
		r1 = -1,-1,-1; 
		

		p2 = 0.75,-0.35,-1; 
		q2 = 1,-0.35,-1; 
		r2 = 1,-0.6,-1 ; 
	

		PolygonType polygon1 , polygon2 ;
		polygon1.append_vertex(p1); polygon1.append_vertex(q1); polygon1.append_vertex(r1);
		polygon2.append_vertex(p2); polygon2.append_vertex(q2); polygon2.append_vertex(r2);
		CPPUNIT_ASSERT (true == predicate_polygon_polygon (polygon1, polygon2 ));		

		IntersectResult<Value> _intr; 	
		std::vector<std::vector<Vector<Value> > > cut_line;
		std::vector<std::vector<Vector<Value> > > opposite_cut_line;
		std::vector<pair <unsigned, unsigned > > hepair_idx ;
		std::vector<pair <unsigned, unsigned > > opposite_hepair_idx; 
		CPPUNIT_ASSERT (true == intersect_polygon_polygon_coplanar (polygon1, polygon2, _intr, cut_line, opposite_cut_line, hepair_idx, opposite_hepair_idx));

				
	}
	catch (const char * msg)
	{
		std::cerr<<msg<<std::endl;
		throw (msg);			
	}

}

void test_pol_pol_convex_2d()
{
	try
	{
	Vector<Value> p1, q1, r1 ;  // First triangle. 
	Vector<Value> p2, q2, r2 ;  // Second triangle. 
//[1,0] [0,0] [0,-1] 
//[0,1] [-1,1] [0,0] 
	PolygonType polygon1 , polygon2 ;

	//p1 = 1, 0 ; q1 = 0, 0; r1 = 0, -1; 
	//p2 = 0, 1 ; q2 = -1, 1; r2= 0, 0;

	//p1 = -0.25,-0.25; q1 = -0.25,-0.5; r1 = -0,-0.25;
	//p2 = 0.15,-0.25; q2 = 0.15,-0.5; r2 = 0.4,-0.25;

	
//	p1 = -1,-0,-0.25; q1 = -1,-0.25,-0.5; r1 = -1,-0.25,-0.25; 
//	p2 = -1,0.4,-0.25; q2 = -1,0.15,-0.5; r2 = -1,0.15,-0.25; 



		p1 = 1,1,1; 
		q1= -1,1,1; 
		r1 = -1,-1,1;

		p2 = 0.8,1.4,1; 
		q2 = -1.2,1.4,1; 
		r2 = -1.2,-0.6,1;


		std::cout<<"Hello";

	polygon2.append_vertex(p1); polygon1.append_vertex(q1); polygon1.append_vertex(r1);
	polygon1.append_vertex(p2); polygon2.append_vertex(q2); polygon2.append_vertex(r2);

	IntersectResult<Value> intr ;
	CPPUNIT_ASSERT( true == predicate_polygon_polygon (polygon1, polygon2 ));
//	CPPUNIT_ASSERT (true == intersect_polygon_polygon_coplanar(polygon1, polygon2, intr));
//	CPPUNIT_ASSERT (true == intersect_conv_polygon_polygon (polygon1, polygon2, intr)); 
	}

	catch (const char * msg)
	{
		std::cout<<msg<<std::endl;
	}

}

int main(int argc, char * argv[])
{
	//test_pol_pol_convex_03();
	test_pol_pol_convex_2d();
	/*
	test_tri_tri_3d_co_01(); 
	test_tri_tri_3d_co_02();
	test_tri_tri_3d_co_03();
	test_tri_tri_3d_co_04();
	test_tri_tri_3d_co_05(); 
	test_tri_tri_3d_co_06();
	test_tri_tri_3d_co_07(); 
	test_tri_tri_3d_co_08();
	test_tri_tri_3d_co_09();
	test_tri_tri_3d_co_10();
	*/


	//Pol1 [0,1,1] [0,1,0] [-1,1,0] 
	//Pol2 [1,1,0] [1,1,-1] [0,1,0]

	return 0;
}
